package com.balloon.servlet;

import com.balloon.io.UserDAO;
import com.balloon.logic.UserBean;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * This class is used for controlling the front and back communcation
 */
public class RegisterServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserBean user = new UserBean();

        user.setEmailAddress(request.getParameter("email"));
        user.setFirstName(request.getParameter("firstname"));
        user.setLastName(request.getParameter("lastname"));
        user.setPassword(request.getParameter("password"));

        UserDAO.register(user);

        HttpSession session = request.getSession(true);

        session.setAttribute("currentuser", user);


        response.sendRedirect("home.jsp");
    }
}
